//
//  FreshHot.swift
//  LoveFreshBeen
//
//  Created by Gao on 17/2/9.
//  Copyright © 2017年 Odm. All rights reserved.
//

import UIKit

class Goods: NSObject {
    //*************************商品模型默认属性**********************************
    /// 商品ID
    var id: String?
    /// 商品姓名
    var name: String?
    var brand_id: String?
    /// 超市价格
    var market_price: String?
    var cid: String?
    var category_id: String?
    /// 当前价格
    var partner_price: String?
    var brand_name: String?
    var pre_img: String?
    
    var pre_imgs: String?
    /// 参数
    var specifics: String?
    var product_id: String?
    var dealer_id: String?
    /// 当前价格
    var price: String?
    /// 库存
    var number: Int = -1
    /// 买一赠一
    var pm_desc: String?
    var had_pm: Int = -1
    /// urlStr
    var img: String?
    /// 是不是精选 0 : 不是, 1 : 是
    var is_xf: Int = 0
    
    //*************************商品模型辅助属性**********************************
    // 记录用户对商品添加次数
    var userBuyNumber: Int = 0
}


class FreshHot: NSObject {
    
    var page: Int = -1
    var code: Int = -1
    var msg: String?
    var data: [Goods]?
    
    // 返回容器类中的所需要存放的数据类型 (以 Class 或 Class Name 的形式)。
    class func modelContainerPropertyGenericClass() -> [AnyHashable: Any] {
        return ["data": Goods.self]
    }
    
    class func loadFreshHotData(_ completion:(_ data: FreshHot?, _ error: NSError?) -> Void) {
        guard let path = Bundle.main.path(forResource: "首页新鲜热卖", ofType: nil) else{
            return
        }
        
        let url = URL(fileURLWithPath: path)
        
        guard let jsonString = try? String(contentsOf: url) else{
            return
        }
        
        let freshHot = FreshHot.yy_model(withJSON: jsonString)
        
        if freshHot != nil {
            completion(freshHot, nil)
        }
    }
    
}
